#pragma once

#include "mode.hpp"

#include "qbe/src/ecs/query.hpp"

#include <unordered_map>

#include <functional>
#include <variant>

namespace qbe::state {

using AllModeType = std::variant<DrawingModeType, EditingModeType, SelectModeType>;

template <typename ModeType>
bool isModeType(const AllModeType mode) {
  return std::holds_alternative<ModeType>(mode);
}

template <typename ModeType>
ModeType getModeType(const AllModeType mode) {
  return std::get<ModeType>(mode);
}

using ExitCallback = std::function<void(ecs::Query&, AllModeType)>;

class ModeExitManager {
 public:
  void add(AllModeType targetMode, const ExitCallback& callBack);
  void exit(ecs::Query&, AllModeType targetMode, AllModeType newMode);
  ExitCallback cj_exitCall;
 private:
  std::unordered_map<DrawingModeType, std::vector<ExitCallback>> drawing_mode_exitCall;
  std::unordered_map<EditingModeType, std::vector<ExitCallback>> editing_mode_exitCall;
  std::unordered_map<SelectModeType, std::vector<ExitCallback>> select_mode_exitCall;
};

}  // namespace qbe::state